package csu.jpetstore.jpetstore.service;

import csu.jpetstore.jpetstore.domain.AdminRolePermission;
import csu.jpetstore.jpetstore.repository.AdminRolePermissionRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class AdminRolePermissionService {
    @Autowired
    AdminRolePermissionRepository adminRolePermissionRepository;

    public List<Integer> getPermissionIdByRoleId(int id){
        List<AdminRolePermission> adminRolePermissions = adminRolePermissionRepository.findAllByRoleId(id);
        List<Integer> permissions = new ArrayList<>();
        for (AdminRolePermission adminRolePermission : adminRolePermissions) {
            permissions.add(adminRolePermission.getPermissionId());
        }
        return permissions;
    }
    public List<Integer> getPermissionIdByRoleId(List<Integer> ids){
        List<Integer> permissions = new ArrayList<>();
        for (Integer id : ids) {
            permissions.addAll(getPermissionIdByRoleId(id));
        }
        return permissions;
    }
}
